home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14781 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  38 lines

  1. Path: news.compuserve.com!newsmaster
  2. From: Philippe Verdy <100105.3120@compuserve.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: HELP: Getting the address of member functions
  5. Date: 2 Apr 1996 00:23:43 GMT
  6. Organization: CompuServe Incorporated
  7. Message-ID: <4jps2f$lhj@dub-news-svc-6.compuserve.com>
  8. NNTP-Posting-Host: ad15-078.compuserve.com
  9.  
  10. 079519@bud.swin.edu.au (John Joseph Newbigin) s'Θcrit :
  11. > I am writing a serial port driver class in BC3.1.  It is interrupt driven so I 
  12. > need an interrupt function that can be set to the required int. vector.  I can do 
  13. > this using a normal function but it can not access the class data and so needs 
  14. > global vars. and hence, defeats the purpose of a class.
  15. > Does anyone know how to get the address of member functions so I can overcome this 
  16. > problem?
  17. > --
  18. Your interrupt function has to be static !
  19. This is because a non-static member function has an implicit
  20. and hidden argument which is the reference to the instance
  21. object on which the member function applies.
  22. And interrupt functions do not have parameters (except
  23. processor registers which have no type).
  24. So your interrupt function must access to at least one
  25. static object to find the reference to the data it needs
  26. to manage.
  27. I suggest that you build a standard class with only static
  28. member functions, and a unique data member, which would
  29. be of class type. Then create a static global pointer or
  30. object of this class to receive the instance which contains
  31. interrupt context data.
  32. Your static member interrupt function will use this static
  33. object to find access to any non static object to use...
  34.